<template>
  <div class="contaiter">
    <el-form
      ref="projectExperience"
      :model="projectExperience"
      label-position="left"
      label-width="150px"
      :rules="rules"
    >
      <el-form-item label="项目名称" required prop="projectName">
        <span slot="label" class="left-label">
          <span calss="cn-label">项目名称</span><br />
          <span class="en-label">Project Name</span>
        </span>
        <el-input
          v-model="projectExperience.projectName"
          placeholder="请输入项目名称"
          style="width: 50%"
        />
      </el-form-item>
      <el-form-item label="项目时间" required prop="endTime">
        <span slot="label" class="left-label">
          <span calss="cn-label">项目时间</span><br />
          <span class="en-label">Project Period</span>
        </span>
        <el-date-picker
          v-model="projectExperience.endTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目描述" required prop="projectDescription">
        <span slot="label" class="left-label">
          <span calss="cn-label">项目描述</span><br />
          <span class="en-label">Project Description</span>
        </span>
        <el-input
          v-model="projectExperience.projectDescription"
          placeholder="更完善的项目信息有助于HR快速找到你为保护隐私，请不要填写手机，QQ，微信等联系方式"
          type="textarea"
          maxlength="2000"
          show-word-limit
          :rows="4"
        />
      </el-form-item>
      <el-form-item label=" ">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submitForm('projectExperience')"
          >确定</el-button
        >
        <el-popconfirm
          title="确定删除吗？"
          class="delete-icon"
          @confirm="deleteConfirm"
          v-if="showDel"
        >
          <i class="delete-icon" slot="reference"></i>
        </el-popconfirm>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      educateClassy: [
        { label: "全日制", value: "1" },
        { label: "非全日制", value: "0" },
      ],
      projectExperience: {
        projectName: "", //项目名称
        beginTime: "", //项目开始时间
        endTime: "", //项目结束时间
        projectDescription: "", //项目描述
      },
      rules: {
        projectName: [
          { required: true, message: "请输入项目名称", trigger: "blur" },
        ],
        endTime: [
          { required: true, message: "请选择项目时间", trigger: "change" },
        ],
        projectDescription: [
          { required: true, message: "请输入项目描述", trigger: "blur" },
        ],
      },
      index: null,
      showDel: false,
    };
  },
  methods: {
    businessAreaChange(e) {
      console.log(e);
    },
    handleCityChange(e) {
      console.log(e);
    },
    cancel() {
      this.projectExperience = {
        projectName: "", //项目名称
        beginTime: "", //项目开始时间
        endTime: "", //项目结束时间
        projectDescription: "", //项目描述
      };
      this.showDel = false;
      this.index = null;
      this.$parent.$parent.$parent.closeFun("projectExperience");
      this.$nextTick(() => {
        this.$refs["projectExperience"].clearValidate();
      });
    },
    deleteConfirm() {
      this.$parent.$parent.$parent.deleteFun("projectExperience", this.index);
      this.cancel();
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let data = JSON.parse(JSON.stringify(this.projectExperience));
          let arr = data.endTime;
          data.beginTime = arr[0].split("T")[0];
          data.endTime = arr[1].split("T")[0];
          this.$parent.$parent.$parent.upDate(
            "projectExperience",
            data,
            this.index
          );
          this.cancel();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    init(data, index) {
      data = JSON.parse(JSON.stringify(data));
      data.resignationTime = [data.entryTime, data.resignationTime];
      this.projectExperience = data;
      this.index = index;
      this.showDel = true;
    },
  },
  created() {},
  mounted() {},
};
</script>

<style lang="less" scoped>
.delete-icon {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  display: inline-block;
  width: 32px;
  height: 32px;
  background: url("../../../assets/images/delete_icon.png") no-repeat center
    center / cover;
}
/deep/ .el-textarea__inner {
  padding-right: 65px;
}
/deep/ .el-date-editor .el-range-separator {
  padding: 0 !important;
}
</style>
